using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using Csla.Validation;

namespace BlazeApps.Template
{
    [Serializable()]
    public class TemplateHeaderChild : Csla.ReadOnlyBase<TemplateHeaderChild>
    {
        #region Business Properties and Methods

        //declare members
        private Guid _templateid = Guid.NewGuid();
        private string _templatename = string.Empty;
        private int _numberofplaceholders = 0;
        private int _templateusage = 0;

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid templateid
        {
            get
            {
                CanReadProperty("templateid", true);
                return _templateid;
            }
        }

        public string templatename
        {
            get
            {
                CanReadProperty("templatename", true);
                return _templatename;
            }
        }

        public int numberofplaceholders
        {
            get
            {
                CanReadProperty("numberofplaceholders", true);
                return _numberofplaceholders;
            }
        }

        public int templateusage
        {
            get
            {
                CanReadProperty("templateusage", true);
                return _templateusage;
            }
        }

        protected override object GetIdValue()
        {
            return _templateid;
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in TemplateHeaderChild
            //AuthorizationRules.AllowRead("templateid", "TemplateHeaderChildReadGroup");
            //AuthorizationRules.AllowRead("templatename", "TemplateHeaderChildReadGroup");
            //AuthorizationRules.AllowRead("numberofplaceholders", "TemplateHeaderChildReadGroup");

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static TemplateHeaderChild GetTemplateHeaderChild(SafeDataReader dr)
        {
            return new TemplateHeaderChild(dr);
        }

        private TemplateHeaderChild(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);
        }

        private void FetchObject(SafeDataReader dr)
        {
            _templateid = dr.GetGuid("templateid");
            _templatename = dr.GetString("templatename");
            _numberofplaceholders = dr.GetInt32("numberofplaceholders");
            _templateusage = dr.GetInt32("templateusage");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
